population_vars <-c("rhs_lnnewpop",
                     "rhs_largemetro",
                     "rhs_popdensity",
                     "rhs_lnnewpopGrL0")

violence_vars <- paste(rep(paste("rhs_",
                                   c("guerr",
                                     "par",
                                     "gov",
                                     "attacks",
                                     "violence",
                                     "violenceDUM",
                                     "violenceHIGHDUM",
                                     "violspike"),
                                   sep=""),
                             each=2),
                         c(paste0("_v", colo_version, "L0"), 
                           paste0("_v", colo_version, "L1")),
                         sep="")

remoteness_vars <- c("rhs_p_main_roads",
                     "rhs_np_main_roads",
                     "rhs_p_sec_roads",
                     "rhs_np_sec_roads",
                     "rhs_dirt_roads",
                     "rhs_den_p_main_roads",
                     "rhs_den_np_main_roads",
                     "rhs_den_p_sec_roads",
                     "rhs_den_np_sec_roads",
                     "rhs_den_dirt_roads")
elections_vars <- c("rhs_elec_al_turnout",
                    "rhs_elec_ca_turnout",
                    "rhs_elec_se_turnout",
                    "rhs_elec_d_nat",
                    "rhs_elec_d_president",
                    "rhs_elec_d_loc",
                    "rhs_elec_d_mayor",
                    "rhs_elec_hhi_ca",
                    "rhs_elec_F_ca",
                    "rhs_elec_P_ca",
                    "rhs_elec_hhi_se",
                    "rhs_elec_F_se", 
                    "rhs_elec_P_se",
                    "rhs_elec_margin_1_ca",
                    "rhs_elec_margin_1_se",
                    "rhs_elec_s_1st_al",
                    "rhs_elec_s_1st_ca",
                    "rhs_elec_s_2nd_ca",
                    "rhs_elec_s_1st_se",
                    "rhs_elec_s_2nd_se",
                    "rhs_elec_leaning_1_ca_Rest", 
                    "rhs_elec_leaning_1_ca_CRight",
                    "rhs_elec_leaning_1_ca_CLeft", 
                    "rhs_elec_leaning_1_se_Rest",
                    "rhs_elec_leaning_1_se_CRight", 
                    "rhs_elec_leaning_1_se_CLeft",
                    "rhs_elec_leaning_2_ca_Rest", 
                    "rhs_elec_leaning_2_ca_CRight",
                    "rhs_elec_leaning_2_ca_CLeft",
                    "rhs_elec_leaning_2_se_Rest",
                    "rhs_elec_leaning_2_se_CRight", 
                    "rhs_elec_leaning_2_se_CLeft",
                    "rhs_elec_party_1st_al_Other", 
                    "rhs_elec_party_1st_al_Liberal",
                    "rhs_elec_party_1st_al_Conserv", 
                    "rhs_elec_party_1st_ca_Other",
                    "rhs_elec_party_1st_ca_Liberal",
                    "rhs_elec_party_1st_ca_Conserv",
                    "rhs_elec_party_1st_se_Other", 
                    "rhs_elec_party_1st_se_Liberal",
                    "rhs_elec_party_1st_se_Conserv", 
                    "rhs_elec_party_2nd_ca_Other",
                    "rhs_elec_party_2nd_ca_Liberal", 
                    "rhs_elec_party_2nd_ca_Conserv",
                    "rhs_elec_party_2nd_se_Other", 
                    "rhs_elec_party_2nd_se_Liberal",
                    "rhs_elec_party_2nd_se_Conserv")

geography_vars <- c("rhs_areakm",
                    "rhs_inhabitable",
                    "rhs_optimal_sugar",
                    "rhs_suboptimal_sugar",
                    "rhs_suitable_sugar",
                    "rhs_nosuitable_sugar",
                    "rhs_optimal_palm",
                    "rhs_suboptimal_palm",
                    "rhs_suitable_palm",
                    "rhs_nosuitable_palm",
                    "rhs_averageslope",
                    "rhs_stdslope",
                    "rhs_slightlyflatp",
                    "rhs_slightlyslopedp",
                    "rhs_moderatelyslopedp",
                    "rhs_stronglyslopedp",
                    "rhs_slightlysteepp",
                    "rhs_moderatelysteepp",
                    "rhs_stronglysteepp",
                    "rhs_averagewater",
                    "rhs_stdwater",
                    "rhs_mriv",
                    "rhs_sriv",
                    "rhs_triv",
                    "rhs_dmriv2",
                    "rhs_dsriv2",
                    "rhs_dtriv2",
                    "rhs_splain",
                    "rhs_shill",
                    "rhs_smount",
                    "rhs_svall",
                    "rhs_swat",
                    "rhs_shill2",
                    "rhs_smount2",
                    "rhs_srug",
                    "rhs_maxslop")

governmentfinance_vars <- c("rhs_dnprevtot",
                            "rhs_dnpspendtot",
                            "rhs_dnprevcurrent",
                            "rhs_dnpspendcurrent",
                            "rhs_dnpdeficitcurr",
                            "rhs_dnpspendcap",
                            "rhs_dnprevtax",
                            "rhs_dnprevnontax",
                            "rhs_dnpspendfun",
                            "rhs_dnprevtaxland",
                            "rhs_dnprevtaxind",
                            "rhs_dnpspendperson",
                            "rhs_dnprevcapL0",
                            "rhs_dnprevcapL1",
                            "rhs_dnprevcapL2",
                            "rhs_dnpdeficittotL0",
                            "rhs_dnpdeficittotL1",
                            "rhs_dnpdeficittotL2",
                            "rhs_dnpfinancingL0",
                            "rhs_dnpfinancingL1",
                            "rhs_dnpfinancingL2",
                            "rhs_dnprevcurtranL0",
                            "rhs_dnprevcurtranL1",
                            "rhs_dnprevcurtranL2",
                            "rhs_dnpspendcapformL0",
                            "rhs_dnpspendcapformL1",
                            "rhs_dnpspendcapformL2",
                            "rhs_dnpcreditL0",
                            "rhs_dnpcreditL1",
                            "rhs_dnpcreditL2",
                            "rhs_dnpbalL0",
                            "rhs_dnpbalL1",
                            "rhs_dnpbalL2",
                            "rhs_dnpspendgenL0",
                            "rhs_dnpspendgenL1",
                            "rhs_dnpspendgenL2",
                            "rhs_dnpspendtranL0",
                            "rhs_dnpspendtranL1",
                            "rhs_dnpspendtranL2")
history_vars <- c("rhs_CrownEmployees",
                 "rhs_NonMilEmployees",
                 "rhs_ColStatePresence",
                 "rhs_CityStatus",
                 "rhs_RoyalRoad",
                 "rhs_SlaveShare1843",
                 "rhs_SlavesDum1843",
                 "rhs_Indians",
                 "rhs_Encomiendas",
                 "rhs_EncomiendasDum",
                 "rhs_GoldMineDum",
                 "rhs_FoundDate",
                 "rhs_Pop1843",
                 "rhs_MissPop1843")


distribution_vars <- c("rhs_gini_land",
                       "rhs_ubn93",
                       "rhs_lqi93")
comshock_interaction_vars <- paste(rep(paste("rhs_",
                                            c("cofintxlinternalp",
                                              "oilprod88xlop",
                                              "mining78xlgoldp",
                                              "coalres78xlcoalp",
                                              "mining78xlsilverp",
                                              "mining78xlplatp"),
                                            sep=""),
                                      each=3),
                                  c("L0", "L1", "L2"),
                                  sep="")
commprice_vars <- paste(rep(paste("rhs_",
                                  c("lcoffee_arabicas",
                                    "loil_wti",
                                    "lgold",
                                    "lcoal",
                                    "lsilver",
                                    "lplatinum"),
                                  sep=""),
                            each=3),
                        c("L0", "L1", "L2"),
                        sep="")

comshock_vars <- c(comshock_interaction_vars,
                   commprice_vars)
production_vars <- c("rhs_oilprod88",
                    "rhs_coalres78",
                    "rhs_mining78",
                    "rhs_cofint")

comNoInt_vars <- c(commprice_vars,
                   production_vars)

comshockAll_vars <- c(comshock_vars, production_vars)

illicitproduction_vars <- c("rhs_hpoppy1994",
                           "rhs_dpoppy1994",
                           "rhs_hcoca1994",
                           "rhs_dcoca1994",
                           "rhs_errad1994",
                           "rhs_derrad1994")
illicitprice_vars <- paste(rep(paste("rhs_",
                                    c("cocahec_col",
                                      "coca_eradcol",
                                      "cocahec_bol",
                                      "cocahec_peru",
                                      "cocahec_tot",
                                      "coca_eradbol"),
                                    sep=""),
                              each=3),
                          c("L0", "L1", "L2"),
                          sep="")
illicit_interaction_vars <- c()

illicitshock_vars <- c(illicitprice_vars, illicit_interaction_vars)

illicit_all_vars <- c(illicitshock_vars, illicitproduction_vars)


climateshock_vars <- c("rhs_rain_deviationL0",
                       "rhs_rain_deviationL1",
                       "rhs_rain_deviationL2",
                       "rhs_temp_deviationL0",
                       "rhs_temp_deviationL1",
                       "rhs_temp_deviationL2")

climatehist_vars <- c("rhs_rain_average",
                        "rhs_rain_sd",
                        "rhs_temp_average",
                        "rhs_temp_sd")

dmz_vars <- c("rhs_dmz_dum",
             "rhs_dmz_distance")
baseweights_vars <- c("rhs_usmil_bases6")
basetime_vars <- paste(rep(paste("rhs_",
                                 c("usmil_lrmil_col",
                                   "usmil_lrnar_col",
                                   "usmil_lrmilnar_col"),
                                 sep=""),
                           each=3),
                       c("L0", "L1", "L2"),
                       sep="")
base_interaction_vars <- paste(rep(paste("rhs_usmil_bases6x",
                                         c("lrmilnar_col",
                                           "lrmil_col",
                                           "lrnar_col"),
                                         sep=""),
                                   each=3),
                               c("L0", "L1", "L2"),
                               sep="")
bases_vars <- c(basetime_vars, baseweights_vars, base_interaction_vars)
bases_noint_vars <- c(basetime_vars, baseweights_vars)
bases_noweight_vars <- c(basetime_vars, base_interaction_vars)


# Make larger groups of variables

varying_vars <- c(comshock_vars,
                  governmentfinance_vars,
                  illicitshock_vars,
                  climateshock_vars,
                  bases_vars,
                  elections_vars)
fixed_vars <- c(population_vars,
                production_vars,
                geography_vars,
                distribution_vars,
                illicitproduction_vars,
                remoteness_vars,
                climatehist_vars,
                history_vars,
                dmz_vars)
full_vars <- c(violence_vars,
               varying_vars,
               fixed_vars)

table1 <- list(full = full_vars)
table3_pt1 <- list(onlyviolence = violence_vars,
                   violpop = c(population_vars,
                               violence_vars))
table3_pt2 <- list(noviolence = c(varying_vars,
                                  fixed_vars))
table3_pt3 <- list(fullvarying = varying_vars)
table3_pt4 <- list(fullfixed = fixed_vars)

table3 <- c(table3_pt1,
            table3_pt2,
            table3_pt3,
            table3_pt4)
table4 <- list(full = full_vars,
               onlyviolence = violence_vars,
               violpop = c(population_vars,
                           violence_vars),
               noviolence = c(varying_vars,
                              fixed_vars))
table4_pt1 <- list(full = full_vars,
                   onlyviolence = violence_vars)
table4_pt2 <- list(violpop = c(population_vars,
                               violence_vars),
                   noviolence = c(varying_vars,
                                  fixed_vars))

figures_1_2_annual <- list(comshock=c(population_vars,
                                      comshock_vars),  
                           climateshock=c(population_vars,
                                          climateshock_vars),
                           elections=c(population_vars, elections_vars),
                           governmentfinance=c(population_vars, governmentfinance_vars),
                           bases=c(population_vars, bases_vars),
                           illicitshock=c(population_vars, illicitshock_vars))
figures_1_2_slow <- list()

figures_1_2_fixed <- list(population=population_vars,
                          production=c(population_vars, production_vars),
                          distribution=c(population_vars, distribution_vars),
                          climatehist=c(population_vars, climatehist_vars),
                          history=c(population_vars, history_vars),
                          dmz=c(population_vars, dmz_vars),
                          remoteness=c(population_vars, remoteness_vars),
                          geography=c(population_vars, geography_vars),
                          illicitproduction=c(population_vars, illicitproduction_vars)
                          )
figures_1_2 <- c(figures_1_2_fixed,
                 figures_1_2_slow,
                 figures_1_2_annual)

figure_1 = figures_1_2
figure_1_fixed = figures_1_2_fixed
figure_1_slow = figures_1_2_slow
figure_1_annual = figures_1_2_annual

figure_2 = figures_1_2

tableA2 = table1

tableA3_pt1 = table1
tableA3_pt2 = table3_pt1
tableA3_pt3 = table3_pt2
tableA3_pt4 = table3_pt3
tableA3_pt5 = table3_pt4

figure_A1_fixed = figures_1_2_fixed
figure_A1_slow = figures_1_2_slow
figure_A1_annual = figures_1_2_annual

tableA7 = table1
figure_A3_fixed = figures_1_2_fixed
figure_A3_slow = figures_1_2_slow
figure_A3_annual = figures_1_2_annual

labels = c(comshock = "Commodity Shocks",
           production = "Commodity Production",
           governmentfinance = "Government Finance",
           education = "Education",
           geography = "Geography",
           distribution = "Distributional Measures",
           remoteness = "Remoteness",
           illicitproduction = "Drug Production",
           illicitshock = "Drug Production Shocks",
           climateshock = "Weather Shocks",
           climatehist = "Weather History",
           history = "Historical Traits",
           dmz = "DMZ Proximity",
           bases = "US Military Involvement",
           elections = "Electoral",
           priceOnly = "Comm Prices",
           comshockAll = "Comm Prices, Wts, and Ints",
           priceavg ="Commodities with MAs",
           weatheravg = "Weather with MAs")


if (length(full_vars[!(full_vars %in% colnames(dta))]) > 0) {
  print('Missing:')
  print(full_vars[!(full_vars %in% colnames(dta))])
}
